package com.xiaohong.goodsWeb.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import util.AdminToken;

@Configuration
public class TokenRequestInterceptor implements RequestInterceptor {

    public static String token = AdminToken.creatToken(new String[]{"oauth"});

    @Override
    public void apply(RequestTemplate template) {
        /**
         * 从数据库加载查询用户信息
         * 1:没有令牌，Feign调用之前，生成令牌(admin)
         * 2:Feign调用之前，令牌需要携带过去
         * 3:Feign调用之前，令牌需要存放到Header文件中
         * 4:请求->Feign调用->拦截器Request Interceptor->Feign调用之前执行拦截
         */
        //将令牌信息存放到请求头中
        template.header("Authorization","Bearer "+token);
    }
}

